package main

import (
	"TeacherManager/common"
	"TeacherManager/models"
	"TeacherManager/routers"
	"TeacherManager/system"
	"flag"

	"github.com/cihub/seelog"
)

/**
* Created by LONG  on 2018/5/25.
 */

func main() {

	configFilePath := flag.String("C", "conf/conf.yaml", "config file path")
	logConfigPath := flag.String("L", "conf/seelog.xml", "log config file path")
	flag.Parse()

	logger, err := seelog.LoggerFromConfigAsFile(*logConfigPath)
	if err != nil {
		seelog.Critical("err parsing seelog config file", err)
		return
	}
	seelog.ReplaceLogger(logger)
	defer seelog.Flush()

	if err := system.LoadConfiguration(*configFilePath); err != nil {
		seelog.Critical("err parsing config log file", err)
		return
	}
	//seelog.Info("dsds11")
	//dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	//fmt.Println("==========")
	//fmt.Println(dir)
	db, err := models.InitDB()
	if err != nil {
		seelog.Critical("err open databases", err)
		return
	}
	defer db.Close()

	//初始化路由
	router := routers.Init()
	common.Init()
	router.Run(system.GetConfiguration().Addr)
}
